<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>范例</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="v8js.resources.html">« 资源类型</a></li>
      <li style="float: right;"><a href="class.v8js.html">V8Js »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.v8js.html">V8js</a></li>
    <li>范例</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="v8js.examples" class="chapter">
 <h1>范例</h1>

 <p class="para">
  Basic usage
 </p>
 <div class="example" id="example-3852">
  <p><strong>示例 #1 Basic Javascript execution</strong></p>
  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$v8&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">V8Js</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;basic.js&nbsp;*/<br /></span><span style="color: #0000BB">$JS&nbsp;</span><span style="color: #007700">=&nbsp;&lt;&lt;&lt;&nbsp;EOT<br /></span><span style="color: #DD0000">len&nbsp;=&nbsp;print('Hello'&nbsp;+&nbsp;'&nbsp;'&nbsp;+&nbsp;'World!'&nbsp;+&nbsp;"\\n");<br />len;<br /></span><span style="color: #007700">EOT;<br /><br />try&nbsp;{<br />&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$v8</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">executeString</span><span style="color: #007700">(</span><span style="color: #0000BB">$JS</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'basic.js'</span><span style="color: #007700">));<br />}&nbsp;catch&nbsp;(</span><span style="color: #0000BB">V8JsException&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$e</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
  </div>

  <div class="example-contents"><p>以上例程会输出：</p></div>
  <div class="example-contents screen">
<div class="cdata"><pre>
Hello World!
int(13)
</pre></div>
  </div>
 </div>
</div>
</div></div></body></html>